<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: JsCookMenuPortlet.php 314 2008-11-21 17:37:50Z steen.rabol@gmail.com $
 *
 */

Prado::using('Application.Portlets.Portlet');
Prado::using('Application.Portlets.JsCookMenuPortlet.Common.JSCookMenuRecord');
Prado::using('Application.Portlets.JsCookMenuPortlet.Common.JSCookMenuItemRecord');
Prado::using('Application.Common.Data.PortalPageRecord');
Prado::using('Application.Common.Data.PortalSiteMenuRecord');


class JsCookMenuPortlet extends Portlet
{
	private $_menuRecord		= null;
	private $_parentmenuitem	= 0;

	public function onLoad($param)
	{
		parent::onLoad($param);

		$this->_menuRecord = JSCookMenuRecord::finder()->findByPk($this->Parameters['id']);
		if($this->_menuRecord == null)
		{
			$mc			= new JSCookMenuRecord();
			$mc->id		= $this->Parameters['id'];
			$mc->theme	= 'ThemeGray';
			$mc->name	= '';
			$mc->save();

			$this->_menuRecord = $mc;
		}

		if(!$this->Page->IsPostBack)
		{
			$this->dataBind();
		}
	}

	public function dataBind()
	{
		$data	= array();
		$data[] = array('text' => Prado::localize('Gray color'), 'value' => 'ThemeGray');
		$data[] = array('text' => Prado::localize('Like Internet explorer 6'), 'value' => 'ThemeIE');
//		$data[] = array('text' => Prado::localize('Simple panel'), 'value' => 'ThemePanel');
		$data[] = array('text' => Prado::localize('Small black menu'), 'value' => 'ThemeMiniBlack');
		$data[] = array('text' => Prado::localize('Like Microsoft Office'), 'value' => 'ThemeOffice');
		$data[] = array('text' => Prado::localize('Like Microsoft Office 2003'), 'value' => 'ThemeOffice2003');
		$data[] = array('text' => Prado::localize('White color'), 'value' => 'ThemePanel');
		$data[] = array('text' => Prado::localize('Orange color'), 'value' => 'ThemeOrange');
		$data[] = array('text' => Prado::localize('Blue color'), 'value' => 'ThemeBlue');
		$data[] = array('text' => Prado::localize('Red color'), 'value' => 'ThemeRed');
		$data[] = array('text' => Prado::localize('Green color'), 'value' => 'ThemeGreen');
		$data[] = array('text' => Prado::localize('Brown color'), 'value' => 'ThemeBrown');
		$data[] = array('text' => Prado::localize('Custom'), 'value' => 'ThemeCustom');

		$this->Theme->DataSource=$data;
		$this->Theme->dataBind();
		$this->Theme->SelectedValue	= $this->_menuRecord->theme;

		$data	= array();
		$data[] = array('text' => Prado::localize('Horizontal - Down/Right'), 'value' => 'hbr');
		$data[] = array('text' => Prado::localize('Horizontal - Down/Left'), 'value' => 'hbl');
		$data[] = array('text' => Prado::localize('Horizontal - Up/Right'), 'value' => 'hur');
		$data[] = array('text' => Prado::localize('Horizontal - Up/Left'), 'value' => 'hul');
		$data[] = array('text' => Prado::localize('Vertical - Down/Right'), 'value' => 'vbr');
		$data[] = array('text' => Prado::localize('Vertical - Down/Left'), 'value' => 'vbl');
		$data[] = array('text' => Prado::localize('Vertical - Up/Right'), 'value' => 'vur');
		$data[] = array('text' => Prado::localize('Vertical - Up/Left'), 'value' => 'vul');

		$this->Orientation->DataSource=$data;
		$this->Orientation->dataBind();
		$this->Orientation->SelectedValue	= $this->_menuRecord->menuorientation;

		$this->ddlSiteMenu->DataSource	= PortalSiteMenuRecord::finder()->findAllByactive(1);
		$this->ddlSiteMenu->dataBind();
		if($this->MenuRecord->sitemenuid)
			$this->ddlSiteMenu->SelectedValue	= $this->MenuRecord->sitemenuid;
	}

	public function SaveContent($sender,$param)
	{
		$mc = JSCookMenuRecord::finder()->findByPk($this->Parameters['id']);

		if($mc === null)
		{
			$mc			= new JSCookMenuRecord();
			$mc->id		= $this->Parameters['id'];
			$mc->theme	= 'ThemeGray';
		}
		else
		{
			$mc->theme				= $this->Theme->SelectedValue;
			$mc->menuorientation	= $this->Orientation->SelectedValue;
		}
		$mc->sitemenuid	= $this->ddlSiteMenu->SelectedValue;

		$mc->save();
		$this->_menuRecord = JSCookMenuRecord::finder()->findByPk($this->Parameters['id']);
		$this->dataBind();
	}

	public function getMenuRecord()
	{
		return $this->_menuRecord;
	}
}
?>